********************************************************************************
*				MERGE DATA TOGETHER TO CREATE MAIN.DTA
********************************************************************************

// LOAD CENSUS AND VOTECAL DATA
use ../data_intermediate/votecal_census_2002_2010.dta,clear
// ADD TIME TO SHOOTING VARS AND SHOOTING CHARACTERISTICS 
merge 1:1 cb elec_yr using ../data_intermediate/main_shootings.dta, assert(3) nogen
// ADD HOMICIDE DATA
merge 1:1 cb elec_yr using ../raw/crimes/cb_homicides, assert(1 2 3) keep(1 3) nogen
replace num_homicide = 0 if num_homicide==.
replace any_homicide = 0 if any_homicide==.
// ADD VALIDATION OF RACE-SPECIFIC VOTING ESTIMATES
merge 1:1 cb elec_yr using ../raw/voting_validation/voting_validation.dta, assert(3) nogen
// KEEP KEY VARIABLES FOR ANALYSIS
keep 	all all_c00 black_c00 hisp_c00 all_c10 black_c10 hisp_c10 ///
		all_c02 black_c02 hisp_c02 blhi_qu_c00 blhi_qu_c10 blhi_qu_c02 age_10_17_qu  ///
		cb CT CBG CB elec_yr elec_id num_homicide ///
		multi_treat pop_dec pop_dec_unrestricted pop_change ///
		pct_white pct_black pct_hisp pct_api pct_other ///
		sample_main sample_unarmed_known sample_armed_known ///
		tau treat treat_post tp_resident tp_not_resident ///
		tp_blackhispanic tp_whiteasian /// 
		reg_02 reg reg_dem reg_rep reg_ind ///
		reg_black reg_white reg_hisp reg_whiteasian reg_blackhispanic ///
		reg_1834 reg_3554 reg_55pl ///
		reg_0to3 reg_4to7 reg_8to11 reg_12to15 ///
		vote vote_dem vote_rep vote_ind ///
		vote_black vote_white vote_hisp vote_whiteasian vote_blackhispanic ///
		vote_black_validate vote_white_validate ///
		vote_1834 vote_3554 vote_55pl  ///
		vote_0to3 vote_4to7 vote_8to11 vote_12to15 
save ../data/main.dta,replace 
